package org.linlinjava.litemall.admin.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallSysConfig;
import org.linlinjava.litemall.db.service.LitemallSysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: renshuai
 * @date: 2019/3/4 15:45
 * @Description:
 */
@RestController
@RequestMapping("/admin/config")
@Validated
public class AdminConfigController {

    @Autowired
    private LitemallSysConfigService sysConfigService;
    @RequiresPermissions("admin:config:list")
    @RequiresPermissionsDesc(menu={"系统管理" , "配置管理"}, button="查询")
    @GetMapping("/list")
    public Object list() {
        return  ResponseUtil.ok(sysConfigService.getList());
    }

    @RequiresPermissions("admin:config:update")
    @RequiresPermissionsDesc(menu={"系统管理" , "配置管理"}, button="编辑")
    @PostMapping("/update")
    public Object update(@RequestBody LitemallSysConfig sysConfig) {
        int count = sysConfigService.updateSysConfig(sysConfig);
        if (count != 1) {
            return ResponseUtil.fail(500, "更新失败");
        }
        return ResponseUtil.ok();
    }
}
